function [the_reduced_data, all_reduced_labels] = reduce_data_to_particular_trials(the_data, all_labels, labels_for_which_trials_to_use, ids_to_use)

% This function will reduce the_data and all_labels so that only trials that match particular critera 
% (as given by the IDs in the labels_for_which_trials_to_use and the ID numbers to use based on ids_to_use).
% should add more extensive explanation...


%==========================================================================

%     This code is part of the Neural Decoding Toolbox.
%     Copyright (C) 2011 by Ethan Meyers (emeyers@mit.edu)
% 
%     This program is free software: you can redistribute it and/or modify
%     it under the terms of the GNU General Public License as published by
%     the Free Software Foundation, either version 3 of the License, or
%     (at your option) any later version.
% 
%     This program is distributed in the hope that it will be useful,
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
%     GNU General Public License for more details.
% 
%     You should have received a copy of the GNU General Public License
%     along with this program.  If not, see <http://www.gnu.org/licenses/>.
    
%==========================================================================  






for iNeuron = 1:length(the_data)
    
    
    
   the_inds = []; 
   for iIDsToUse = 1:length(ids_to_use)   
       the_inds = union(the_inds, find(labels_for_which_trials_to_use{iNeuron} == ids_to_use(iIDsToUse)));
   end
    
    
   the_reduced_data{iNeuron} = the_data{iNeuron}(the_inds, :);
   
   
   the_label_names = fieldnames(all_labels);
   
   for iLabels = 1:length(the_label_names)
       
      eval(['all_reduced_labels.' the_label_names{iLabels} '{iNeuron} = all_labels.' the_label_names{iLabels} '{iNeuron}(the_inds);']);
            
   end
   
    
   
end


































